package com.wgworkshop.pems.common;

/**
 * 统一请求相应结果。
 * Created by wlc on 2017/7/2.
 */
public class ResponseData<T> {
    private int code;
    private String message;
    private T data;

    public ResponseData<T> success() {
        this.code = 0;
        return this;
    }

//    public ResponseData<T> success(String message) {
//        success();
//        this.message = message;
//        return this;
//    }

    public ResponseData<T> success(T data) {
        success();
        this.message = "OK";
        this.data = data;
        return this;
    }

    public ResponseData<T> success(String message, T data) {
        this.message = message;
        this.data = data;
        return this;
    }

    public ResponseData<T> failure(int code) {
        this.code = code;
        return this;
    }

    public ResponseData<T> failure(int code, String message) {
        failure(code);
        this.message = message;
        return this;
    }

    public ResponseData<T> failure(int code, T data) {
        failure(code);
        this.data = data;
        return this;
    }

    public ResponseData<T> failure(int code, String message, T data) {
        failure(code, message);
        this.data = data;
        return this;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
